# urllib 获取weibo个人信息页面

import urllib.parse
import urllib.request
import urllib.error

url = "https://www.ipip.net/"
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0",
    # "Cookie": "WEIBOCN_WM=90207_90001; _T_WM=acb241c6945ba3fc0c92270b86a7b1e7; SCF=AnwP02sxRAhtUMHQ4manxISqz_jjob6dx2weH8BwRrAhiO-0KwSIyhZfK3b9SVtbpqyCAsB1MXmJBJijlmzFQFw.; SUB=_2A25I_XxsDeRhGeBM71cU9CbKyjqIHXVoc_GkrDV6PUJbktANLXjFkW1NRP4sdVb4pRz_LduJT7GhGV6hWZXrxi8u; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9WFA2mAsz-Cv1D7wTc7uC9wb5NHD95QceoBfSKBRSo2cWs4DqcjGwJxAIhqcSntt; SSOLoginState=1710820412; ALF=1713412412"

}
request = urllib.request.Request(url, headers=headers)
proxies={
    "http":"180.105.88.154:21230"
}
proxy_handler = urllib.request.ProxyHandler(proxies=proxies)

try:
    opener = urllib.request.build_opener(proxy_handler)
    response = opener.open(urllib.request.Request(url, headers=headers))
    content = response.read().decode("utf-8")
    with open("1.html", "w", encoding="utf8") as file:
        file.write(content)
except urllib.error.HTTPError as e:
    print(e)
